package com.jiangjiang.eshop.pay.Builder;

import com.jiangjiang.eshop.order.dto.OrderInfoDTO;
import com.jiangjiang.eshop.pay.constant.PayTransactionStatus;
import com.jiangjiang.eshop.pay.dto.PayTransactionDTO;

/**
 * @Author Jianghaowen
 * @Date 2021/9/30
 * @Description: TODO
 * @Version V1.0
 **/
public class PayTransactionBuilder {

    /**
     * 支付交易流水
     */
    private final PayTransactionDTO payTransaction = new PayTransactionDTO();

    /**
     * 获取builder对象
     *
     * @return builder 对象
     */
    public static PayTransactionBuilder get() {
        return new PayTransactionBuilder();
    }


    /**
     * 构造参数私有化
     */
    private PayTransactionBuilder() {

    }

    /**
     * 设置与订单相关的数据
     * @param order 订单数据
     * @return builer 对象
     */
    public PayTransactionBuilder setOrderRelatedData(OrderInfoDTO order) {
        payTransaction.setOrderInfoId(order.getId());
        payTransaction.setOrderNo(order.getOrderNo());
        payTransaction.setPayableAmount(order.getPayableAmount());
        payTransaction.setUserAccountId(order.getUserAccountId());
        payTransaction.setTransactionChannel(order.getPayType());
        return this;
    }

    /**
     *
     * @return
     */
    public PayTransactionBuilder initStatue(){
        payTransaction.setStatus(PayTransactionStatus.UNPAYED);
        return this;
    }

    /**
     * 对象创建
     * @return
     */
    public PayTransactionDTO create(){
        return payTransaction;
    }


}
